/*
 * @Author: your name
 * @Date: 2021-12-27 12:10:44
 * @LastEditTime: 2021-12-27 20:34:29
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue\vue-douban-pc\src\utils\index.js
 */
// 1.浏览器永久存储   window.localStorage

export const Local = {
    //设置永久存储
    set(key, val) {
        window.localStorage.setItem(key, JSON.stringify(val));
    },
    //获取永久存储
    get(key) {
        let json = window.localStorage.getItem(key);
        try {
            return JSON.parse(json);
        } catch (error) {
            return json
        }
    },
    //移除永久存储
    remove(key) {
        window.localStorage.removeItem(key);
    }
}

// 2.浏览器临时存储   window.sessionStorage

export const Session = {
    //设置临时存储
    set(key, val) {
        window.sessionStorage.setItem(key, JSON.stringify(val));
    },
    //获取临时存储
    get(key) {
        let json = window.sessionStorage.getItem(key);
        try {
            return JSON.parse(json);
        } catch (error) {
            return json
        }
    },
    //移除临时存储
    remove(key) {
        window.sessionStorage.removeItem(key);
    }
}

